package emulator.shell.GUI.debugger;

public class CodePanelPosition {
	private int visible_lines;
	private int current_position;
	private int current_range;
	private int selected_address;

	public CodePanelPosition(int visible_lines, int current_position, int current_range)
	{
		this.visible_lines = visible_lines;
		this.current_position = current_position;
		this.current_range = current_range;
		this.selected_address = -1;
	}

	public int getVisibleLines() {
		return visible_lines;
	}

	public void setVisibleLines(int visible_lines) {
		this.visible_lines = visible_lines;
	}

	public int getCurrentPosition() {
		return current_position;
	}

	public void setCurrentPosition(int desired_position) {
		current_position = Math.min(Math.max(0, desired_position), getCurrentRange() - getVisibleLines());
	}

	public int getCurrentRange() {
		return current_range;
	}

	public void setCurrentRange(int current_range) {
		this.current_range = current_range;
	}

	/**
	 * @return the selectedLine
	 */
	public int getSelectedAddress() {
		return selected_address;
	}

	/**
	 * @param selectedLine the selectedLine to set
	 */
	public void setSelectedAddress(int selectedLine) {
		this.selected_address = selectedLine;
	}

	boolean isVisibleLine(int index) {
		return getCurrentPosition() <= index && index < getCurrentPosition() + getVisibleLines();
	}
	
	boolean isSelectedAddress(int address) {
		return address == selected_address;
	}
}